<template>
  <div class="dashboard-container">
    <!-- 顶部标题栏 -->
    <div class="header">
      <div class="system-title">加热炉链路追踪系统</div>
      <div class="header-buttons">
        <button class="btn-real-time">实时监控</button>
        <button class="btn-trace">钢坯 追溯</button>
        <button class="btn-trace">钢坯 追溯</button>
        <button class="btn-trace">钢坯 追溯</button>
        <button class="btn-history">历史详情</button>
      </div>
    </div>

    <!-- 中间内容区域 -->
    <div class="main-content">
      <div class="panel">
        <div class="panel-title">整体控制参数实时更新</div>
        <div class="panel-content">
          <!-- 参数实时更新内容 -->
          <div class="data-grid">
            <div class="data-item" v-for="(item, index) in controlParams" :key="index">
              <div class="data-label">{{ item.label }}</div>
              <div class="data-value">{{ item.value }}{{ item.unit }}</div>
            </div>
          </div>
        </div>
      </div>

      <div class="panel">
        <div class="panel-title">炉段控制参数实时更新</div>
        <div class="panel-content">
          <!-- 炉段参数内容 -->
          <div class="furnace-status">
            <div class="furnace-visualization">
              <div class="furnace-temp-indicator" v-for="(section, idx) in furnaceSections" :key="idx">
                <div class="section-name">{{ section.name }}</div>
                <div class="temp-bar">
                  <div class="temp-fill" :style="{ height: section.tempPercent + '%' }"></div>
                </div>
                <div class="temp-value">{{ section.temperature }}°C</div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="panel">
        <div class="panel-title">最近10钢坯出炉评价</div>
        <div class="panel-content">
          <!-- 钢坯评价内容 -->
          <div class="evaluation-table">
            <div class="table-header">
              <div class="table-col">钢坯编号</div>
              <div class="table-col">出炉时间</div>
              <div class="table-col">温度</div>
              <div class="table-col">质量评价</div>
            </div>
            <div class="table-row" v-for="(slab, index) in recentSlabs" :key="index">
              <div class="table-col">{{ slab.id }}</div>
              <div class="table-col">{{ slab.time }}</div>
              <div class="table-col">{{ slab.temp }}°C</div>
              <div class="table-col">
                <span :class="['quality-tag', slab.quality]">{{ slab.qualityText }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部面板 -->
    <div class="footer">
      <div class="panel">
        <div class="panel-title">板坯实时位置、温度等信息跟踪</div>
        <div class="panel-content">
          <!-- 板坯跟踪信息 -->
          <div class="tracking-container">
            <div class="tracking-visual">
              <div class="furnace-line">
                <div class="furnace-part" v-for="(part, idx) in furnaceParts" :key="idx">
                  <div class="part-name">{{ part.name }}</div>
                  <div class="slab-position" v-if="part.hasSlab">
                    <div class="slab-icon"></div>
                  </div>
                </div>
              </div>
            </div>
            <div class="tracking-data">
              <div class="tracking-item">
                <span class="tracking-label">当前板坯:</span>
                <span class="tracking-value">B20231025-08</span>
              </div>
              <div class="tracking-item">
                <span class="tracking-label">实时温度:</span>
                <span class="tracking-value">856°C</span>
              </div>
              <div class="tracking-item">
                <span class="tracking-label">位置:</span>
                <span class="tracking-value">加热段</span>
              </div>
              <div class="tracking-item">
                <span class="tracking-label">运行状态:</span>
                <span class="tracking-value status-normal">正常运行</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HeatingFurnaceDashboard',
  data() {
    return {
      controlParams: [
        { label: '炉内压力', value: 125, unit: 'Pa' },
        { label: '燃气流量', value: 2580, unit: 'm³/h' },
        { label: '空气流量', value: 18500, unit: 'm³/h' },
        { label: '炉温设定', value: 1250, unit: '°C' },
        { label: '排烟温度', value: 280, unit: '°C' },
        { label: '氧含量', value: 3.2, unit: '%' }
      ],
      furnaceSections: [
        { name: '预热段', temperature: 850, tempPercent: 65 },
        { name: '加热段', temperature: 1250, tempPercent: 95 },
        { name: '均热段', temperature: 1280, tempPercent: 100 }
      ],
      recentSlabs: [
        { id: 'B20231025-01', time: '10:25:36', temp: 1256, quality: 'good', qualityText: '优良' },
        { id: 'B20231025-02', time: '10:31:12', temp: 1248, quality: 'good', qualityText: '优良' },
        { id: 'B20231025-03', time: '10:36:45', temp: 1262, quality: 'good', qualityText: '优良' },
        { id: 'B20231025-04', time: '10:42:23', temp: 1235, quality: 'normal', qualityText: '合格' },
        { id: 'B20231025-05', time: '10:48:07', temp: 1271, quality: 'good', qualityText: '优良' },
        { id: 'B20231025-06', time: '10:53:50', temp: 1228, quality: 'normal', qualityText: '合格' },
        { id: 'B20231025-07', time: '10:59:34', temp: 1253, quality: 'good', qualityText: '优良' }
      ],
      furnaceParts: [
        { name: '装料端', hasSlab: false },
        { name: '预热段', hasSlab: true },
        { name: '加热段', hasSlab: false },
        { name: '均热段', hasSlab: false },
        { name: '出料端', hasSlab: false }
      ]
    }
  },
  mounted() {
    // 模拟实时数据更新
    setInterval(() => {
      this.updateData();
    }, 5000);
  },
  methods: {
    updateData() {
      // 随机更新一些数据，模拟实时变化
      this.controlParams.forEach(param => {
        if (param.label === '炉内压力') {
          param.value = 120 + Math.floor(Math.random() * 15);
        } else if (param.label === '炉温设定') {
          param.value = 1245 + Math.floor(Math.random() * 15);
        }
      });

      this.furnaceSections.forEach(section => {
        const variation = Math.floor(Math.random() * 20) - 10;
        section.temperature += variation;
      });
    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Microsoft YaHei", Arial, sans-serif;
}

.dashboard-container {
  width: 100vw;
  height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  background-color: #0a1a35;
  color: #fff;
  overflow: hidden;
}

/* 顶部标题栏样式 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  margin-bottom: 20px;
  background: linear-gradient(90deg, #063e7e 0%, #0a52b3 100%);
  border-radius: 8px;
  padding: 0 30px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.system-title {
  font-size: 32px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 180, 255, 0.7);
}

.header-buttons {
  display: flex;
  gap: 15px;
}

.btn-real-time, .btn-trace, .btn-history {
  background-color: #ffcc00;
  color: #333;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  font-size: 18px;
  box-shadow: 0 0 8px rgba(255, 204, 0, 0.5);
  transition: all 0.3s;
}

.btn-real-time:hover, .btn-trace:hover, .btn-history:hover {
  background-color: #ffd700;
  transform: translateY(-2px);
}

/* 中间内容区域样式 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

.panel {
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(50, 130, 255, 0.3);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.panel-title {
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 15px;
  color: #fff;
  display: flex;
  align-items: center;
}

.panel-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 22px;
  background-color: #00a8ff;
  margin-right: 10px;
  border-radius: 2px;
}

.panel-content {
  color: #eee;
  flex: 1;
}

/* 数据网格样式 */
.data-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.data-item {
  background: rgba(0, 84, 168, 0.3);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
}

.data-label {
  font-size: 16px;
  margin-bottom: 10px;
  color: #ccc;
}

.data-value {
  font-size: 28px;
  font-weight: bold;
  color: #ffcc00;
}

/* 炉段状态可视化 */
.furnace-status {
  height: 100%;
  display: flex;
  align-items: center;
}

.furnace-visualization {
  display: flex;
  width: 100%;
  justify-content: space-around;
  align-items: flex-end;
  height: 80%;
}

.furnace-temp-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.temp-bar {
  width: 80px;
  height: 80%;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  margin: 10px 0;
  position: relative;
  overflow: hidden;
}

.temp-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  background: linear-gradient(0deg, #ff9900, #ff5500);
  transition: height 1s ease;
}

.temp-value {
  font-size: 18px;
  font-weight: bold;
  color: #ffcc00;
}

.section-name {
  font-size: 18px;
  font-weight: bold;
}

/* 评价表格样式 */
.evaluation-table {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.table-header, .table-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr;
  padding: 12px 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.table-header {
  background: rgba(0, 84, 168, 0.3);
  font-weight: bold;
  border-radius: 4px 4px 0 0;
}

.table-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.quality-tag {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
}

.quality-tag.good {
  background: rgba(0, 200, 83, 0.2);
  color: #00c853;
}

.quality-tag.normal {
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
}

/* 底部面板样式 */
.footer {
  height: 200px;
}

.tracking-container {
  display: flex;
  height: 100%;
}

.tracking-visual {
  flex: 2;
  display: flex;
  align-items: center;
}

.tracking-data {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-left: 30px;
}

.furnace-line {
  display: flex;
  width: 100%;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 8px;
}

.furnace-part {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  flex: 1;
}

.part-name {
  margin-bottom: 15px;
  font-weight: bold;
}

.slab-position {
  width: 100%;
  height: 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.slab-icon {
  width: 60%;
  height: 20px;
  background: #ffcc00;
  border-radius: 3px;
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

.tracking-item {
  margin-bottom: 15px;
  display: flex;
}

.tracking-label {
  color: #ccc;
  margin-right: 10px;
  min-width: 80px;
}

.tracking-value {
  font-weight: bold;
  color: #ffcc00;
}

.status-normal {
  color: #4caf50;
}

/* 响应式调整 */
@media (max-width: 1920px) {
  .system-title {
    font-size: 28px;
  }

  .btn-real-time, .btn-trace, .btn-history {
    padding: 10px 20px;
    font-size: 16px;
  }

  .data-value {
    font-size: 24px;
  }
}
</style>